﻿using Furion;
using Furion.VirtualFileServer;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;

namespace iLeak.Web.Core
{
    public class Startup : AppStartup
    {
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddConsoleFormatter();
            services.AddControllers().AddInjectWithUnifyResult();
            services.AddRazorPages();
            services.AddServerSideBlazor();

            services.AddControllersWithViews()
                .AddAppLocalization(settings =>
                {
                    // 集成第三方 json 配置
                    services.AddJsonLocalization(options => options.ResourcesPath = settings.ResourcesPath);
                }); // 注册多语言
        }

        public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseExceptionHandler("/Error");
                app.UseHsts();
            }

            // 配置多语言，必须在 路由注册之前
            app.UseAppLocalization();


            app.UseHttpsRedirection(); // 启用 HTTPS 重定向
            app.UseStaticFiles();

            app.UseRouting();
            app.UseCorsAccessor();


            app.UseAuthentication();
            app.UseAuthorization();

            app.UseInject();


            #region 定时任务看板

            app.UseScheduleUI();

            app.UseScheduleUI(options =>
            {
                options.RequestPath = "/schedule"; // Furion 4.8.5.6+ 版本支持，必须以 / 开头且不以 / 结尾
                options.DisableOnProduction = false;
                // options.VirtualPath = "/job";
            });

            #endregion

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllerRoute(
                    name: "default",
                    pattern: "{controller=Home}/{action=Index}/{id?}");

                endpoints.MapBlazorHub();

                // endpoints.MapHub<ChatHub>("/hubs/chathub");


                endpoints.MapFallbackToPage("/_Host");
            });
        }
    }
}